#!/bin/bash

: ${1?"You need provide command to watch (Will execute it until it exit with 0 status)! Example:
`basename $0` '[ \$( dig @TEZIS.MANAGEDNS1.ESTBOXES.COM alexeevs.info cname | grep -i cname | wc -l ) -gt 2 ]' 'Cname for alexeevs.info updated.' 50 'mplayer do-do.mp3'"
}

MESSAGE=${2-"Updated!!!"}
INTERVAL=${3-60}
DONECMD=${4-'wget -c http://temp/web_play.php -q -O /dev/null'}

source "$(dirname $0)/SHARED/notify.bash"

	while ! eval "$1" ; do
		date;
		sleep $INTERVAL;
	done;

	if [ "$MESSAGE" ]; then
		notify "$MESSAGE"
	fi

	#If present command - do it
	if [ "$DONECMD" ]; then
		eval "$DONECMD"
	fi
